home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #2 / Ham Radio 2000 - Volume 2.iso / HAMV2 / MISC / HCAL-27 / CUSTCAP.BAS (.txt) < prev    next >
Encoding:
GW-BASIC  |  1997-01-28  |  4.5 KB  |  168 lines

  1. 10  'CUSTCAP - 09 sep 92 rev. 27 SEP 96   'adapted from CUSTOHM
  2. 20  IF EX$=""THEN EX$="EXIT"
  3. 30  IF PROG$=""THEN GO$=EX$ ELSE GO$=PROG$
  4. 40  COMMON EX$,PROG$
  5. 50  CLS:KEY OFF
  6. 60  COLOR 7,0,1
  7. 70  UL$=STRING$(80,205)
  8. 80  U$="####,###"
  9. 90  U1$="##"
  10. 100  U2$="###,###.##"
  11. 110  U3$="#####.#"
  12. 120  U4$="####.#"
  13. 130  DIM Q(20,3)      'quantity,value,net capacitance
  14. 140  DIM R(24)        '24 combinations
  15. 150  '.....standard capacitor values
  16. 160  DATA 1,1.1,1.2,1.3,1.5,1.6,1.8,2.0,2.2,2.4,2.7,3
  17. 170  DATA 3.3,3.6,3.9,4.3,4.7,5.1,5.6,6.2,6.8,7.5,8.2,9.1
  18. 180  '.....load data arrays
  19. 190  FOR Z=1 TO 24
  20. 200  READ R(Z)
  21. 210  NEXT Z
  22. 220  '
  23. 230  '.....start
  24. 240  CLS
  25. 250  COLOR 15,2
  26. 260  PRINT " CAPACITORS in PARALLEL";TAB(57);"by George Murphy VE3ERP ";
  27. 270  COLOR 1,0:PRINT STRING$(80,223);
  28. 280  COLOR 7,0
  29. 290  T=(8)     'tab for text
  30. 300  GOSUB 1290  'text
  31. 310  PRINT
  32. 320  COLOR 0,7:LOCATE CSRLIN,22
  33. 330  PRINT " Press 1 to continue or 0 to EXIT....."
  34. 340  COLOR 7,0
  35. 350  Z$=INKEY$:IF Z$=""THEN 350
  36. 360  IF Z$="0"THEN CLS:CHAIN GO$
  37. 370  IF Z$="1"THEN 410
  38. 380  GOTO 350
  39. 390  '
  40. 400  '.....start
  41. 410  VIEW PRINT 3 TO 24:CLS:VIEW PRINT:LOCATE 3
  42. 420  PRINT " Press number in < > to select capacitance unit:"
  43. 430  PRINT UL$;
  44. 440  PRINT "   <1> pF
  45. 450  PRINT "   <2) >F
  46. 460  PRINT UL$;
  47. 470  Z$=INKEY$:IF Z$=""THEN 470
  48. 480  IF Z$="1"THEN O$="pF":GOTO 510
  49. 490  IF Z$="2"THEN O$=">F":GOTO 510
  50. 500  GOTO 470
  51. 510  PRINT " ENTER: Value of custom capacitor (";O$;")";:INPUT RC
  52. 520  IF RC<1 AND O$=">F"THEN RC=RC*10^6:O$="pF"
  53. 530  VIEW PRINT 3 TO 24:CLS:VIEW PRINT:LOCATE 3
  54. 540  '
  55. 550  '.....calculate capacitor banks
  56. 560  N=0
  57. 570  FOR Y=1 TO 10            'no. of capacitors loop
  58. 580   RX=RC/Y                 'value of capacitor
  59. 590   M=1                     'multiplier
  60. 600    FOR Z=1 TO 24
  61. 610     IF R(Z)*M>RX THEN 660
  62. 620    NEXT Z
  63. 630   M=M*10
  64. 640   GOTO 600
  65. 650  '
  66. 660   R1=R(Z-1)*M                      'next lower capacitor
  67. 670   IF Z=1 THEN R1=R(12)*M/10
  68. 680   N=N+1                            'counter
  69. 690   Q(N,1)=Y                         'quantity of capacitors in bank
  70. 700   Q(N,2)=R1                        'value of each capacitor
  71. 710   Q(N,3)=R1*Y                      'net capacitance of capacitor bank
  72. 720  '
  73. 730   R2=R(Z)*M                        'next higher capacitor
  74. 740   N=N+1                            'counter
  75. 750   Q(N,1)=Y                         'quantity of capacitors in bank
  76. 760   Q(N,2)=R2                        'value of each capacitor
  77. 770   Q(N,3)=R2*Y                      'net capacitance of capacitor bank
  78. 780  NEXT Y
  79. 790  '
  80. 800  '******START SORT******
  81. 810  SN=N
  82. 820  SM=SN
  83. 830  SM=INT(SM/2):IF SM=0 THEN 920
  84. 840  SK=SN-SM:SJ=1
  85. 850  SI=SJ
  86. 860  SL=SI+SM
  87. 870  IF Q(SI,3)<=Q(SL,3)THEN 900
  88. 880  FOR A=1 TO 3:SWAP Q(SI,A),Q(SL,A):NEXT A
  89. 890  SI=SI-SM:IF SI>0 THEN 860
  90. 900  SJ=SJ+1:IF SJ>SK THEN 830
  91. 910  GOTO 850
  92. 920  '******SORT COMPLETED******
  93. 930  '
  94. 940  '....display data
  95. 950  FOR Z=1 TO N
  96. 960   PC=ABS(Q(Z,3)-RC)/RC*100                   '% off target
  97. 970   IF Q(Z,1)=1 THEN P$=STRING$(13,32)+"=":ELSE P$=" in parallel ="
  98. 980   IF Q(Z-1,3)<=RC AND Q(Z,3)>RC THEN GOSUB 1210
  99. 990   IF PC<=5 THEN COLOR 15,2 ELSE COLOR 7,0
  100. 1000  PRINT TAB(3);
  101. 1010   PRINT USING U1$;Q(Z,1);                    'print quantity
  102. 1020   R=Q(Z,2):V$=O$                             'value
  103. 1030    R$=STR$(R)
  104. 1040    L$=STR$(LEN(R$)-3)
  105. 1050    Q$=LEFT$(R$,2)
  106. 1060    Q$=MID$(R$,3,1)
  107. 1070    Q$=LEFT$(L$,2)
  108. 1080   IF R<10 THEN X$=U4$ ELSE X$=U$
  109. 1090  IF RC<100 THEN U$="######.#"
  110. 1100   PRINT"  @";USING U$;R;                     'print value
  111. 1110   PRINT " ";V$;P$;
  112. 1120   PRINT USING U2$;Q(Z,3);:PRINT " ";O$;      'print net capacitance of bank
  113. 1130   IF Q(Z,3)=RC THEN PRINT "      ON TARGET !   ":GOTO 1150
  114. 1140   PRINT USING U3$;PC;:PRINT " % off target"  'discrepancy
  115. 1150  NEXT Z
  116. 1160  COLOR 7,0
  117. 1170  PRINT UL$;
  118. 1180  GOSUB 1550             'screen dump
  119. 1190  GOTO 230
  120. 1200  '
  121. 1210  '.....hi-lite sought resistance
  122. 1220  COLOR 14,4
  123. 1230  PRINT " TARGET CAPACITANCE";
  124. 1240  PRINT STRING$(13,".");USING U2$;RC;
  125. 1250  PRINT " ";O$;STRING$(20,32)
  126. 1260  COLOR 7,0
  127. 1270  RETURN
  128. 1280  '
  129. 1290  '.....text page
  130. 1300  PRINT TAB(T);
  131. 1310  PRINT "This program designs custom capacitors that will be very close to"
  132. 1320  PRINT TAB(T);
  133. 1330  PRINT "almost any reasonable value, using standard common capacitors"
  134. 1340  PRINT TAB(T);
  135. 1350  PRINT "connected in parallel."
  136. 1360  PRINT
  137. 1370  PRINT TAB(T);
  138. 1380  PRINT "The program calculates several combinations of capacitors, any of"
  139. 1390  PRINT TAB(T);
  140. 1400  PRINT "which will provide a net capacitance close to your target value."
  141. 1410  PRINT
  142. 1420  PRINT TAB(T);
  143. 1430  PRINT "Each combination displayed shows what percentage it is off the"
  144. 1440  PRINT TAB(T);
  145. 1450  PRINT "target capacitance. Combinations within 5% of the target value"
  146. 1460  PRINT TAB(T);
  147. 1470  PRINT "are high-lighted."
  148. 1480  PRINT
  149. 1490  PRINT TAB(T);
  150. 1500  PRINT "Just enter the value of the custom capacitor you want and the"
  151. 1510  PRINT TAB(T);
  152. 1520  PRINT "computer will do the rest !"
  153. 1530  RETURN
  154. 1540  '
  155. 1550  'HARDCOPY
  156. 1560  GOSUB 1670:LOCATE 25,2:COLOR 14,6
  157. 1570  PRINT " Press 1 to print screen, 2 to print screen & ";
  158. 1580  PRINT "advance paper, or 3 to continue.";:COLOR 7,0
  159. 1590  Z$=INKEY$:IF Z$="3"THEN GOSUB 1670:RETURN
  160. 1600  IF Z$="1"OR Z$="2"THEN GOSUB 1670:GOTO 1620
  161. 1610  GOTO 1590
  162. 1620  FOR QX=1 TO 24:FOR QY=1 TO 80
  163. 1630  LPRINT CHR$(SCREEN(QX,QY));
  164. 1640  NEXT QY:NEXT QX
  165. 1650  IF Z$="2"THEN LPRINT CHR$(12)
  166. 1660  GOTO 1560
  167. 1670  LOCATE 25,1:PRINT STRING$(80,32);:RETURN
  168.